package com.lovo.project.servlet.service;

import com.lovo.project.enums.ServiceCodeEnum;
import com.lovo.project.exception.OurException;
import com.lovo.project.service.ServiceService;
import com.lovo.project.service.impl.ServiceServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DeleteByServiceIdServlet",value = "/service/deleteByServiceId")

public class DeleteByServiceIdServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            Integer serviceId = Integer.parseInt(request.getParameter("serviceId"));
            ServiceService serviceService =new ServiceServiceImpl();
            Integer integer = serviceService.deleteService(serviceId);
            response.getWriter().print(ResultVO.success().add(integer).toJson());
        }catch (OurException e){
            response.getWriter().print(ResultVO.fail(e.getCodeEnum()).toJson());
        }catch (Exception e1){
            response.getWriter().print(ResultVO.fail(ServiceCodeEnum.SERVICE_UNKNOWN_ERROR).toJson());
        }
    }

    @Override    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
